package com.jftone.bh.app.action;

import com.jftone.bh.app.model.NtbUser;
import com.jftone.bh.app.service.ReferrerService;
import org.apache.log4j.Logger;
import org.jftone.annotation.Autowired;
import org.jftone.annotation.Controller;
import org.jftone.exception.ActionException;
import org.jftone.util.IData;
import org.jftone.util.StringUtil;

import java.util.List;


@Controller(mapping="/referrerAction")
public class ReferrerAction extends BaseAction {

	private Logger logger = Logger.getLogger(ReferrerAction.class);
	
	@Autowired
	private ReferrerService service;

	public void index() throws ActionException {
		try {
			this.render("referrer/referrer_tree.html");
		} catch (Exception e) {
			logger.error("查询推荐树错误" + e.getMessage(), e);
			throw new ActionException("查询推荐树错误" + e.getMessage(), e);
		}
	}

	public void queryReferrerList() throws ActionException {
		IData<String, Object> data = getData();
		String userId = data.getString("userId", "");
		String type = data.getString("type", "1");
		if(StringUtil.isEmpty(userId) || StringUtil.isEmpty(type) || !StringUtil.isNumber(userId) || !StringUtil.isNumber(type)){
			this.send(1,"参数错误");
			return;
		}
		try {
			List<IData<String, Object>> list = service.queryReferrerList(userId,type);
			this.send(list);
		} catch (Exception e) {
			logger.error("查询推荐树错误" + e.getMessage(), e);
			throw new ActionException("查询推荐树错误" + e.getMessage(), e);
		}
	}

}
